package sea.explore;

import sea.util.WinHelper;

/**
 *
 * This class builds the layout of Save Option
 * 
 * @author  Zhirun Ding
 * 
 * Created on 04/07/2012
 * 
 */

public class ExploreOutputTypeForm extends javax.swing.JDialog {
    
    /** Creates new form ExploreOuputTypeForm */
    public ExploreOutputTypeForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        storeButtonGroup = new javax.swing.ButtonGroup();
        saveFileButtonGroup = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        singlefileRadioButton = new javax.swing.JRadioButton();
        filenameLabe = new javax.swing.JLabel();
        filenameText = new javax.swing.JTextField();
        oneFilePerRadioButton = new javax.swing.JRadioButton();
        savetofileCheckBox = new javax.swing.JCheckBox();
        templateLabel = new javax.swing.JLabel();
        templateText = new javax.swing.JTextField();
        backButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        helpButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sea.SimHyAGui.class).getContext().getResourceMap(ExploreOutputTypeForm.class);
        setTitle(resourceMap.getString("ExploreOutputTypeForm.title")); // NOI18N
        setName("ExploreOutputTypeForm"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setName("jPanel2"); // NOI18N

        saveFileButtonGroup.add(singlefileRadioButton);
        singlefileRadioButton.setText(resourceMap.getString("Single file.text")); // NOI18N
        singlefileRadioButton.setEnabled(false);
        singlefileRadioButton.setName("Single file"); // NOI18N

        filenameLabe.setText(resourceMap.getString("filenameLabe.text")); // NOI18N
        filenameLabe.setEnabled(false);
        filenameLabe.setName("filenameLabe"); // NOI18N

        filenameText.setText(resourceMap.getString("filenameText.text")); // NOI18N
        filenameText.setEnabled(false);
        filenameText.setName("filenameText"); // NOI18N

        saveFileButtonGroup.add(oneFilePerRadioButton);
        oneFilePerRadioButton.setText(resourceMap.getString("oneFilePerRadioButton.text")); // NOI18N
        oneFilePerRadioButton.setEnabled(false);
        oneFilePerRadioButton.setName("oneFilePerRadioButton"); // NOI18N

        savetofileCheckBox.setText(resourceMap.getString("savetofileCheckBox.text")); // NOI18N
        savetofileCheckBox.setName("savetofileCheckBox"); // NOI18N
        savetofileCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                savetofileCheckBoxStateChanged(evt);
            }
        });

        templateLabel.setText(resourceMap.getString("templateLabel.text")); // NOI18N
        templateLabel.setEnabled(false);
        templateLabel.setName("templateLabel"); // NOI18N

        templateText.setText(resourceMap.getString("templateText.text")); // NOI18N
        templateText.setEnabled(false);
        templateText.setName("templateText"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(oneFilePerRadioButton)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(filenameLabe)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(filenameText, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE))
                            .addComponent(singlefileRadioButton)
                            .addComponent(savetofileCheckBox)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(templateLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(templateText, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(savetofileCheckBox)
                .addGap(14, 14, 14)
                .addComponent(singlefileRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filenameLabe)
                    .addComponent(filenameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(oneFilePerRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(templateLabel)
                    .addComponent(templateText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        backButton.setText(resourceMap.getString("backButton.text")); // NOI18N
        backButton.setName("backButton"); // NOI18N
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        helpButton.setText(resourceMap.getString("helpButton.text")); // NOI18N
        helpButton.setName("helpButton"); // NOI18N
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(233, Short.MAX_VALUE)
                .addComponent(cancelButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(backButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(helpButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(backButton)
                    .addComponent(cancelButton)
                    .addComponent(helpButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        toExploreOutputTypeExpression();
        this.dispose();
    }//GEN-LAST:event_backButtonActionPerformed

    private void savetofileCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_savetofileCheckBoxStateChanged
        filenameLabe.setEnabled(savetofileCheckBox.isSelected());
        singlefileRadioButton.setEnabled(savetofileCheckBox.isSelected());
        filenameText.setEnabled(savetofileCheckBox.isSelected());
        oneFilePerRadioButton.setEnabled(savetofileCheckBox.isSelected());
        templateLabel.setEnabled(savetofileCheckBox.isSelected());
        templateText.setEnabled(savetofileCheckBox.isSelected());
    }//GEN-LAST:event_savetofileCheckBoxStateChanged

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
        WinHelper.showHelp("explore/saveoption");
    }//GEN-LAST:event_helpButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ExploreOutputTypeForm dialog = new ExploreOutputTypeForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    //generate the range params of explore
    public String toExploreOutputTypeExpression() {
        String s = "";
        
        //store
//        if (allRadioButton.isSelected()) {
//            s += ",store=all";
//        } else if (distributionRadioButton.isSelected()) {
//            s += ",store=distribution";
//        } else if (finalRadioButton.isSelected()) {
//            s += ",store=final";
//        } else if (trajectoryRadioButton.isSelected()) {
//            s += ",store=trajectory";
//        }
        
        //save to files
        if (savetofileCheckBox.isSelected()) {
            //file
            if (singlefileRadioButton.isSelected()) {
                if (filenameText.getText().length() > 0) {
                    s += ",file=" + filenameText.getText();
                }
            }

            //template
            if (oneFilePerRadioButton.isSelected() && templateText.getText().length() > 0) {
                s += ",template=" + templateText.getText();
            }
        }
        
        //System.out.println(s);
        return s;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel filenameLabe;
    private javax.swing.JTextField filenameText;
    private javax.swing.JButton helpButton;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton oneFilePerRadioButton;
    private javax.swing.ButtonGroup saveFileButtonGroup;
    private javax.swing.JCheckBox savetofileCheckBox;
    private javax.swing.JRadioButton singlefileRadioButton;
    private javax.swing.ButtonGroup storeButtonGroup;
    private javax.swing.JLabel templateLabel;
    private javax.swing.JTextField templateText;
    // End of variables declaration//GEN-END:variables
    
}
